﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Sharp.DataTransferObject;


namespace Sharp.Platform.Owin
{
    [Serializable]
    public class SharpUser : Microsoft.AspNet.Identity.IUser<Guid>
    {
        public SharpUser()
        {
            Face = "/Content/Images/Example/a1.jpg";
        }
        public SharpUser(UserDTO dto)
        {
            Face = "/Content/Images/Example/a1.jpg";
            this.Id = dto.Id;
            this.UserName = dto.UserName;
            this.Password = dto.Password;
            this.Permissions = dto.Permissions;
        }
        /// <summary>
        /// 用户编号
        /// </summary>
        public Guid Id
        {
            get;
            set;
        }

        /// <summary>
        /// 
        /// </summary>
        [DisplayName("登录名")]
        public string UserName
        {
            get;
            set;
        }
        public string Face { get; set; }
        /// <summary>
        /// 密码
        /// </summary>
        [DisplayName("密码")]
        public string Password { get; set; }

        /// <summary>
        /// 昵称
        /// </summary>
        [DisplayName("昵称")]
        public string Nick { get; set; }

        /// <summary>
        /// 电邮
        /// </summary>
        [DisplayName("电邮")]
        public string Email { get; set; }

        /// <summary>
        /// 权限
        /// </summary>
        public List<PermissionDTO> Permissions { get; set; }

        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(SharpUserManager manager)
        {
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            return userIdentity;
        }
    }
}